/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgLevelBuff
    {
        private readonly Dictionary<int, CfgLevelBuff> _dataMap;
        private readonly List<CfgLevelBuff> _dataList;


        public TbCfgLevelBuff(ByteBuf _buf)
        {
            //first read common data
            _TbCommonLevelBuff _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonLevelBuff(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgLevelBuff>(size * 3 / 2);
            _dataList = new List<CfgLevelBuff>(size);

            for (int i = 0; i < size; i++)
            {
                CfgLevelBuff _v;
                _v = CfgLevelBuff.DeserializeCfgLevelBuff(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgLevelBuff> DataMap => _dataMap;
        public IReadOnlyList<CfgLevelBuff> DataList => _dataList;

        public CfgLevelBuff Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgLevelBuff] config not found,id:" + key.ToString());

            return null;
        }

        public CfgLevelBuff GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "levelbuff";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgLevelBuff LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgLevelBuff(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgLevelBuff
    {
        private CfgLevelBuff(ByteBuf _buf, _TbCommonLevelBuff _commonData)
        {
            Id = _buf.ReadInt();
            Remark = _buf.ReadString();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field0[dataIndex]; }
            Describe = TableCenter.GetI18NText(_buf.ReadInt());
            InterestDescribe = TableCenter.GetI18NText(_buf.ReadInt());
            ShowType = _buf.ReadInt();
            CoverType = _buf.ReadInt();
            CoverPriority = _buf.ReadInt();
            Duration = _buf.ReadInt();
            MaxStack = _buf.ReadInt();
            TriggerType = _buf.ReadInt();
            TriggerInverval = _buf.ReadInt();
            TriggerCondition = _buf.ReadInt();
            TriggerProbability = _buf.ReadInt();
            TriggerPriority = _buf.ReadInt();
            TriggerMaxNumber = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; Service = _commonData._field1[dataIndex]; }
            SpeedRatio = _buf.ReadInt();

            PostInit();
        }

        internal static CfgLevelBuff DeserializeCfgLevelBuff(ByteBuf _buf, _TbCommonLevelBuff _commonData)
        {
            return new CfgLevelBuff(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 策划备注 ---- 编辑器专用
        /// </summary>
        private string Remark { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 图标资源
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Describe { get; private set; }
        /// <summary>
        /// 趣味描述
        /// </summary>
        public string InterestDescribe { get; private set; }
        /// <summary>
        /// 显示类型
        /// </summary>
        public int ShowType { get; private set; }
        /// <summary>
        /// 覆盖类型
        /// </summary>
        public int CoverType { get; private set; }
        /// <summary>
        /// 覆盖优先级(数字小更高)
        /// </summary>
        public int CoverPriority { get; private set; }
        /// <summary>
        /// 持续时间(毫秒)
        /// </summary>
        public int Duration { get; private set; }
        /// <summary>
        /// 最大叠加层数
        /// </summary>
        public int MaxStack { get; private set; }
        /// <summary>
        /// 触发类型
        /// </summary>
        public int TriggerType { get; private set; }
        /// <summary>
        /// 触发间隔(仅类型2生效
        /// </summary>
        public int TriggerInverval { get; private set; }
        /// <summary>
        /// 触发条件
        /// </summary>
        public int TriggerCondition { get; private set; }
        /// <summary>
        /// 触发几率
        /// </summary>
        public int TriggerProbability { get; private set; }
        /// <summary>
        /// 触发优先级(数字小更高)
        /// </summary>
        public int TriggerPriority { get; private set; }
        /// <summary>
        /// 触发次数(-1为无限)(满足条件才累积)
        /// </summary>
        public int TriggerMaxNumber { get; private set; }
        /// <summary>
        /// 触发的服务
        /// </summary>
        public IReadOnlyList<int> Service { get; private set; }
        /// <summary>
        /// 速度比率(1-100)
        /// </summary>
        public int SpeedRatio { get; private set; }

        /// <summary>
        /// Icon资源全路径
        /// </summary>
        public string Icon_fullPath => $"Res/05_Images/Sprite/Icon_Buff/{Icon}.png";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonLevelBuff
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal _TbCommonLevelBuff(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
